package com.zxf.basic.base

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.lxj.xpopup.XPopup
import com.lxj.xpopup.impl.LoadingPopupView
import com.zxf.basic.expand.flatStatusBar

abstract class BaseActivity : AppCompatActivity() {

    private var loadingProgress: LoadingPopupView? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        if (layout() > 0) {
            setContentView(layout())
        }
        window.flatStatusBar()
        initView()
        initData()
    }

    abstract fun layout(): Int

    abstract fun initView()

    abstract fun initData()

    protected fun showLoading() {
        if (loadingProgress == null) {
            loadingProgress = XPopup.Builder(this)
                .dismissOnBackPressed(true)
                .asLoading("")
        }
        loadingProgress?.show()
    }

    protected fun hideLoading() {
        loadingProgress?.dismiss()
    }

}